//
//  TranManagerCell.m
//  ReceiptDelivery
//
//  Created by 吕晶 on 2020/7/27.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "TranManagerCell.h"

@interface TranManagerCell ()

//@property (nonatomic, strong) TranManagerMenuView *faQiView;
//@property (nonatomic, strong) TranManagerMenuView *shouView;
//@property (nonatomic, strong) TranManagerMenuView *tiDanView;
//@property (nonatomic, strong) TranManagerMenuView *yunFeiChaXunView;
//@property (nonatomic, strong) TranManagerMenuView *kaiPiaoView;
//@property (nonatomic, strong) TranManagerMenuView *yunFeiJieSuanView;
//@property (nonatomic, strong) TranManagerMenuView *heTongView;
//@property (nonatomic, strong) TranManagerMenuView *huoWuView;
//@property (nonatomic, strong) TranManagerMenuView *saoMaView;
//@property (nonatomic, strong) TranManagerMenuView *fanXiangView;
@property (nonatomic, strong) TranManagerMenuView *saoMaView;
@property (nonatomic, strong) TranManagerMenuView *yunDanAddView;
@property (nonatomic, strong) TranManagerMenuView *heTongView;

@end

@implementation TranManagerCell

+ (instancetype)TranManagerCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"TranManagerCell";
    TranManagerCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[TranManagerCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        CGFloat viewW = ScreenW * 0.333333;
        CGFloat viewH = 70;
        
        self.saoMaView = [[TranManagerMenuView alloc] initWithFrame:CGRectMake(0, 20, viewW, viewH)];
        self.saoMaView.iconUrl = @"icon_saomazhuangxiang";
        self.saoMaView.titleStr = @"扫码装箱";
        __weak_self;
        self.saoMaView.clickBlock = ^{
            if (weakself.saoMaBlock) {
                weakself.saoMaBlock();
            }
        };
        [self.contentView addSubview:self.saoMaView];
        
        self.yunDanAddView = [[TranManagerMenuView alloc] initWithFrame:CGRectMake(self.saoMaView.nim_right, 20, viewW, viewH)];
        self.yunDanAddView.iconUrl = @"icon_yundanaddpackage";
        self.yunDanAddView.titleStr = @"运单添加包装";
        self.yunDanAddView.clickBlock = ^{
            if (weakself.yunDanAddBlock) {
                weakself.yunDanAddBlock();
            }
        };
        [self.contentView addSubview:self.yunDanAddView];
        
        self.heTongView = [[TranManagerMenuView alloc] initWithFrame:CGRectMake(self.yunDanAddView.nim_right, 20, viewW, viewH)];
        self.heTongView.iconUrl = @"iocn_hetongguanli";
        self.heTongView.titleStr = @"合同管理";
        self.heTongView.clickBlock = ^{
            if (weakself.heTongBlock) {
                weakself.heTongBlock();
            }
        };
        [self.contentView addSubview:self.heTongView];
        
//        self.yunFeiChaXunView = [[TranManagerMenuView alloc] initWithFrame:CGRectMake(0, 40 + self.faQiView.nim_bottom, viewW, viewH)];
//        self.yunFeiChaXunView.iconUrl = @"Folder";
//        self.yunFeiChaXunView.titleStr = @"运费查询";
//        self.yunFeiChaXunView.clickBlock = ^{
//
//        };
//        [self.contentView addSubview:self.yunFeiChaXunView];
//
//        self.kaiPiaoView = [[TranManagerMenuView alloc] initWithFrame:CGRectMake(self.yunFeiChaXunView.nim_right, self.yunFeiChaXunView.nim_top, viewW, viewH)];
//        self.kaiPiaoView.iconUrl = @"Folder";
//        self.kaiPiaoView.titleStr = @"开票查询";
//        self.kaiPiaoView.clickBlock = ^{
//
//        };
//        [self.contentView addSubview:self.kaiPiaoView];
//
//        self.yunFeiJieSuanView = [[TranManagerMenuView alloc] initWithFrame:CGRectMake(self.kaiPiaoView.nim_right, self.kaiPiaoView.nim_top, viewW, viewH)];
//        self.yunFeiJieSuanView.iconUrl = @"Folder";
//        self.yunFeiJieSuanView.titleStr = @"运费结算";
//        self.yunFeiJieSuanView.clickBlock = ^{
//
//        };
//        [self.contentView addSubview:self.yunFeiJieSuanView];
//
//        self.heTongView = [[TranManagerMenuView alloc] initWithFrame:CGRectMake(0, self.yunFeiChaXunView.nim_bottom + 40, viewW, viewH)];
//        self.heTongView.iconUrl = @"Folder";
//        self.heTongView.titleStr = @"合同管理";
//        self.heTongView.clickBlock = ^{
//            if (weakself.heTongBlock) {
//                weakself.heTongBlock();
//            }
//        };
//        [self.contentView addSubview:self.heTongView];
//
//        self.huoWuView = [[TranManagerMenuView alloc] initWithFrame:CGRectMake(self.heTongView.nim_right, self.heTongView.nim_top, viewW, viewH)];
//        self.huoWuView.iconUrl = @"Folder";
//        self.huoWuView.titleStr = @"货物管理";
//        self.huoWuView.clickBlock = ^{
//            if (weakself.goodManagerBlock) {
//                weakself.goodManagerBlock();
//            }
//        };
//        [self.contentView addSubview:self.huoWuView];
//
//        self.saoMaView = [[TranManagerMenuView alloc] initWithFrame:CGRectMake(self.huoWuView.nim_right, self.huoWuView.nim_top, viewW, viewH)];
//        self.saoMaView.iconUrl = @"Folder";
//        self.saoMaView.titleStr = @"扫码装箱";
//        self.saoMaView.clickBlock = ^{
//            if (weakself.scanInstallBoxBlock) {
//                weakself.scanInstallBoxBlock();
//            }
//        };
//        [self.contentView addSubview:self.saoMaView];
//
//        self.fanXiangView = [[TranManagerMenuView alloc] initWithFrame:CGRectMake(0, self.heTongView.nim_bottom + 40, viewW, viewH)];
//        self.fanXiangView.iconUrl = @"Folder";
//        self.fanXiangView.titleStr = @"返箱管理";
//        self.fanXiangView.clickBlock = ^{
//            if (weakself.backBoxBlock) {
//                weakself.backBoxBlock();
//            }
//        };
//        [self.contentView addSubview:self.fanXiangView];
        
        self.height = self.saoMaView.nim_bottom + 20;
    }
    return self;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end

@interface TranManagerMenuView ()

@property (nonatomic, strong) UIImageView *iconImgView;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UIButton *clickBtn;

@end

@implementation TranManagerMenuView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {

        self.iconImgView = [[UIImageView alloc] initWithFrame:CGRectMake((frame.size.width - 40) * 0.5, 6, 40, 40)];
        [self addSubview:self.iconImgView];
        
        self.titleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, self.iconImgView.nim_bottom + 9, frame.size.width, 15)];
        self.titleLab.textColor = HexColor(0x2B2C44);
        self.titleLab.font = [UIFont systemFontOfSize:14];
        self.titleLab.textAlignment = NSTextAlignmentCenter;
        [self addSubview:self.titleLab];
        
        self.clickBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        [self.clickBtn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.clickBtn];
    }
    return self;
}

- (void)btnClick {
    if (self.clickBlock) {
        self.clickBlock();
    }
}

-(void)setIconUrl:(NSString *)iconUrl {
    _iconUrl = iconUrl;
    self.iconImgView.image = [UIImage imageNamed:iconUrl];
}

-(void)setTitleStr:(NSString *)titleStr {
    _titleStr = titleStr;
    self.titleLab.text = titleStr;
}

@end
